<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('chat_room', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('room_id')->comment("房间id，默认为用户id");
            $table->timestamps();
            $table->unique('room_id');
            $table->index(['updated_at']);
        });
        DB::statement("ALTER TABLE `chat_room` COMMENT='聊天室'");

        Schema::create('chat_room_msg', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('room_id')->comment("房间id，默认为用户id");
            $table->unsignedBigInteger('sender_id')->comment("发言人");
            $table->text('msg')->comment("内容");
            $table->timestamps();
            $table->index(['room_id', 'created_at']);
        });
        DB::statement("ALTER TABLE `chat_room_msg` COMMENT='聊天信息'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('chat_room');
        Schema::dropIfExists('chat_room_msg');
    }
};
